home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / mhs_c.arc / OUTPOST.ARC / COMMANDS.C < prev    next >
C/C++ Source or Header  |  1988-06-27  |  6KB  |  233 lines

  1. /* ****************************** COMMANDS.C ****************************** */
  2. #include "cctypes.h"
  3.  
  4. /*
  5.    The bits in the Month-Day-Year byte are defined as follows:
  6.    YYYYYYY MMMM DDDDD
  7. */
  8. #define    GetMonth(x)        (((x) >> 5) & 0x0F)
  9. #define    GetDay(x)        ((x) & 0x1F)
  10. #define    GetYear(x)        ((((x) >> 9) & 0x7F) + 80)
  11.  
  12. /*
  13.    The bits in the Hour-Minute byte are defined as follows:
  14.    HHHHH MMMMMM
  15. */
  16. #define    GetHour(x)        (((x) >> 11) & 0x1F)
  17. #define    GetMinute(x)    (((x) >> 5) & 0x3F)
  18.  
  19. #define FIRST_WORD_SIZE 37
  20.  
  21. /* extern char Out[]; */
  22. extern char currentLine[];
  23. extern int ErrorsInThisFile;
  24. extern int warningFound;
  25.  
  26. extern int lineNumber;
  27. extern int OutFile;
  28. extern int InFile;
  29. extern int contentsWritten;
  30. /* extern MCB MCBStruct; */
  31. extern char messageBuffer[];
  32. extern char workArea[];
  33. extern XRB XRBRec[];
  34.  
  35. extern void AddCurrentLineToMessageBuffer();
  36. extern int GetNextLine();
  37. extern void GetFirstWord();
  38. extern void BlankLine();
  39. extern void WriteIt();
  40.  
  41. void WriteAttachmentFile();
  42.  
  43. int CreateXRBLine(type)
  44. int type;
  45. {
  46.     int returnCode = NO_ERROR, ccode = 0, bytes, i;
  47.     char fileName[81], temp1[60], temp2[60], *p, *p2;
  48.     char firstWord[FIRST_WORD_SIZE];
  49.  
  50.     static int inMessage = 0;
  51.     static int inTextItem = 0;
  52.     static int hasAttachment = 0;
  53.     extern void InitMCB();
  54.  
  55. /*     Out[0] = '\0'; */
  56.     warningFound = 0;
  57.  
  58.     switch ( type ) {
  59.  
  60.     case DATE:
  61.         WriteIt(currentLine);
  62.         BlankLine();
  63.         break;
  64.     case FROM:
  65.         p = stptok(¤tLine[6], temp1, sizeof(temp1), " ");
  66.         p2 = stptok(p+2, temp2, sizeof(temp2), " ");
  67.         sprintf(temp2, "From: %s at %s", temp1, p2);
  68.         WriteIt(temp2);
  69.         BlankLine();
  70.         break;
  71.     case TO:
  72.         p = stptok(¤tLine[4], temp1, sizeof(temp1), " ");
  73.         p2 = stptok(p+2, temp2, sizeof(temp2), " ");
  74.         sprintf(temp2, "To: %s at %s", temp1, p2);
  75.         WriteIt(temp2);
  76.         BlankLine();
  77.         break;
  78.     case MESSAGE_ID:
  79. /*         AddCurrentLineToMessageBuffer(); */
  80.         break;
  81.     case CONVERSATION_ID:
  82. /*         AddCurrentLineToMessageBuffer(); */
  83.         break;
  84.     case VIA_HOST:
  85. /*         AddCurrentLineToMessageBuffer(); */
  86.         break;
  87.     case SUBJECT:
  88.         WriteIt(currentLine);
  89.         BlankLine();
  90.         break;
  91.     case MESSAGE_TYPE:
  92. /*         AddCurrentLineToMessageBuffer(); */
  93.         break;
  94.     case COPIES_TO:
  95.         /* STUB */
  96.         AddCurrentLineToMessageBuffer();
  97.         break;
  98.     case RE_SENT_BY:
  99.         /* STUB */
  100.         AddCurrentLineToMessageBuffer();
  101.         break;
  102.     case RESPOND_BY:
  103. /*         AddCurrentLineToMessageBuffer(); */
  104.         break;
  105.     case POSSIBILITY:
  106. /*         AddCurrentLineToMessageBuffer(); */
  107.         break;
  108.     case ACTION:
  109.         p = stptok(¤tLine[8], temp1, sizeof(temp1), "\12\15");
  110.         sprintf(temp2, "Subject: %s", temp1);
  111.         WriteIt(temp2);
  112.         BlankLine();
  113.         break;
  114.     case RET_MESSAGE:
  115. /*         AddCurrentLineToMessageBuffer(); */
  116.         break;
  117.     case IN_REPLY_TO:
  118. /*         AddCurrentLineToMessageBuffer(); */
  119.         break;
  120.     case FORM:
  121. /*         AddCurrentLineToMessageBuffer(); */
  122.         break;
  123.     case DOMAIN:
  124. /*         AddCurrentLineToMessageBuffer(); */
  125.         break;
  126.     case COMPLETE_BY:
  127. /*         AddCurrentLineToMessageBuffer(); */
  128.         break;
  129.     case NEW_COMPLETE_BY:
  130. /*         AddCurrentLineToMessageBuffer(); */
  131.         break;
  132.     case ATTACHMENT:
  133.         /* STUB save the name(s) of any attachment files and append them last */
  134.         i=17; /* offset into current line to get the filename */
  135.         goto NetAttach;
  136.         break;
  137.     case NET_ATTACHMENT:
  138.         i=16; /* offset into current line to get the filename */
  139.         /* STUB save the name(s) of any attachment files and append them last */
  140. NetAttach:
  141.         if ( !contentsWritten ) {
  142.             contentsWritten++;
  143.             WriteIt("Contents:");
  144.             BlankLine();
  145.         }
  146.         /* get original fileName */
  147.         p = stptok(¤tLine[i], temp1, sizeof(temp1), " \12\15");
  148.         /* ...and strip off just the file node name */
  149.         temp2[0] = '\0';
  150.         stcgfn(temp2, temp1);
  151.         WriteAttachmentFile(temp2); /* pass in original name */
  152.         break;
  153.     default:
  154.         ;
  155.     }
  156.  
  157.     return(returnCode);
  158. }
  159.  
  160. /* copies the attachment file right into the CC:MAIL file to be imported */
  161. void WriteAttachmentFile(originalName)
  162. char *originalName;
  163. {
  164.     int inHandle, bytesRead, temp = 0, ccode;
  165.     char *buffer, inName[80], tsize[10], searchAttributes, command[256];
  166.     int month, day, year, hour, minute;
  167.     char ampm;
  168.     unsigned t;
  169.     long fSize, fileSize = 0L;
  170.     FILEINFO fileInfo;
  171.  
  172.     buffer = (char *)(malloc(30000)); /* allocate statically ? */
  173.  
  174.     if ( buffer == (char *)NULL )
  175.         return;
  176.  
  177.     /* get the OPARCEL filname */
  178.  
  179.     /* ********* open OPARCEL file ********** */
  180.     sprintf(inName, "Q:OPARCEL\\%s",XRBRec[4].t);
  181.     ccode = FindFirstFile(inName, &fileInfo, (char)0);
  182.     if ( ccode ) goto Out; /* file not found */
  183.     t = fileInfo.fileDate;
  184.     month = GetMonth(t);
  185.     day = GetDay(t);
  186.     year = GetYear(t);
  187.     t = fileInfo.fileTime;
  188.     hour = GetHour(t);
  189.     minute = GetMinute(t);
  190.     if ( hour >= 12 )
  191.         ampm = 'p';
  192.     else
  193.         ampm = 'a';
  194.     if ( hour > 12 )
  195.         hour -= 12;
  196.  
  197.     /* STUB should be opened for exclusive access */
  198.     inHandle = open(inName, O_RDONLY | O_RAW, 0); /* open the OPARCEL file for read */
  199.     if ( inHandle == -1 )
  200.         goto Out;
  201.  
  202.     /* *********** write "File item: <filename>" ********** */
  203.     sprintf(command, "File item: %s %d/%d/%d %d:%d%cm", originalName,
  204.             month, day, year, hour, minute, ampm); /* preserve the original filename */
  205.     WriteIt(command);
  206.     BlankLine();
  207.  
  208.     fSize = lseek(inHandle, 0L, 2);
  209.     sprintf(tsize, "%ld", fSize);
  210.     /* ******** write out the file size ********** */
  211.     WriteIt(tsize);
  212.     BlankLine();
  213.     lseek(inHandle, 0L, 0); /* reset the file pointer */
  214.  
  215.     while ( fSize > 0 ) {
  216.         temp = fSize < 30000 ? fSize : 30000;
  217.  
  218.         bytesRead = read(inHandle, buffer, temp);
  219.  
  220.         if ( bytesRead )
  221.             write(OutFile, buffer, bytesRead);
  222.  
  223.         fSize -= bytesRead;
  224.         fileSize += bytesRead;
  225.     }
  226.  
  227.     close(inHandle);
  228.     unlink(inName);
  229. Out:
  230.     free(buffer);
  231. }
  232.  
  233.